﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Linq;
using System.Net.Mail;

namespace MVCWeb
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            switch (ConfigurationManager.AppSettings["IISVersion"])
            {
                case "6":
                    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                    //Route name, URL with parameters,Parameter defaults
                    routes.MapRoute("Default", "{controller}.aspx/{action}/{id}", new { action = "Index", id = "" });
                    //Route name, URL with parameters,Parameter defaults
                    routes.MapRoute("Root", "", new { controller = "Home", action = "Index", id = "" });
                    break;
                case "7":
                    // For IIS 7. 
                    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

                    routes.MapRoute(
                        "Default",                                              // Route name
                        "{controller}/{action}/{id}",                           // URL with parameters
                        new { controller = "Home", action = "Index", id = "" }); // Parameter defaults
                    break;
            }
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Session_Start(Object sender, EventArgs e)
        {
            Application.Lock();
            MVCWeb.Helpers.VisitorCountHelper.IncreaseSiteVisitorCount();
            Application.UnLock();
        }
    }
}